<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Linux压缩、解压命令 | HelloBin</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/blog/favicon.ico">
    <meta name="description" content="偷得浮生半日闲,人间至味是清欢">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.e16238e2.css" as="style"><link rel="preload" href="/blog/assets/js/app.eeaaf521.js" as="script"><link rel="preload" href="/blog/assets/js/3.f4973d30.js" as="script"><link rel="preload" href="/blog/assets/js/1.c6353690.js" as="script"><link rel="preload" href="/blog/assets/js/15.3a0e6f2f.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.472afe8d.js"><link rel="prefetch" href="/blog/assets/js/11.e226b339.js"><link rel="prefetch" href="/blog/assets/js/12.db3de697.js"><link rel="prefetch" href="/blog/assets/js/13.ab84a112.js"><link rel="prefetch" href="/blog/assets/js/14.3472d173.js"><link rel="prefetch" href="/blog/assets/js/16.0a4356ee.js"><link rel="prefetch" href="/blog/assets/js/17.b1429b08.js"><link rel="prefetch" href="/blog/assets/js/18.fc44351d.js"><link rel="prefetch" href="/blog/assets/js/4.027713aa.js"><link rel="prefetch" href="/blog/assets/js/5.72722b36.js"><link rel="prefetch" href="/blog/assets/js/6.1064904d.js"><link rel="prefetch" href="/blog/assets/js/7.baf14459.js"><link rel="prefetch" href="/blog/assets/js/8.b7d110a6.js"><link rel="prefetch" href="/blog/assets/js/9.e4886eea.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.e16238e2.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1aefc0b4><div data-v-1aefc0b4><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1aefc0b4 data-v-1aefc0b4><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>HelloBin</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>偷得浮生半日闲,人间至味是清欢</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-1aefc0b4><header class="navbar" data-v-1aefc0b4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/logo.png" alt="HelloBin" class="logo"> <span class="site-name">HelloBin</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      学习笔记
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/Golang/" class="nav-link"><i class="undefined"></i>
  Golang
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/MySQL/" class="nav-link"><i class="undefined"></i>
  MySQL
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/Linux/" class="nav-link"><i class="undefined"></i>
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/Nginx/" class="nav-link"><i class="undefined"></i>
  Nginx
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/Redis/" class="nav-link"><i class="undefined"></i>
  Redis
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1aefc0b4></div> <aside class="sidebar" data-v-1aefc0b4><div class="personal-info-wrapper" data-v-39576ba9 data-v-1aefc0b4><img src="/blog/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <!----> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>8</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>9</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      学习笔记
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/Golang/" class="nav-link"><i class="undefined"></i>
  Golang
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/MySQL/" class="nav-link"><i class="undefined"></i>
  MySQL
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/Linux/" class="nav-link"><i class="undefined"></i>
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/Nginx/" class="nav-link"><i class="undefined"></i>
  Nginx
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/Redis/" class="nav-link"><i class="undefined"></i>
  Redis
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>Linux压缩、解压命令</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <!---->
          2022
        </a></span></div></div> <div data-v-1aefc0b4><main class="page"><section><div class="page-title"><h1 class="title">Linux压缩、解压命令</h1> <div data-v-f875f3fc><!----> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>3/20/2022</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>tar</span><span class="tag-item" data-v-f875f3fc>Linux</span></i></div></div> <div class="theme-reco-content content__default"><p>tar</p> <ul><li>-c: 建立压缩档案</li> <li>-x：解压</li> <li>-t：查看内容</li> <li>-r：向压缩归档文件末尾追加文件</li> <li>-u：更新原压缩包中的文件</li></ul> <p>这五个是独立的命令，压缩解压都要用到其中一个，可以和别的命令连用但只能用其中一个。下面的参数是根据需要在压缩或解压档案时可选的。</p> <ul><li>-z：有gzip属性的</li> <li>-j：有bz2属性的</li> <li>-Z：有compress属性的</li> <li>-v：显示所有过程</li> <li>-O：将文件解开到标准输出</li></ul> <p>下面的参数-f是必须的</p> <p>-f: 使用档案名字，切记，这个参数是最后一个参数，后面只能接档案名。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -cf all.tar *.jpg 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包，-f指定包的文件名。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -rf all.tar *.gif 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -uf all.tar logo.gif 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这条命令是更新原来tar包all.tar中logo.gif文件，-u是表示更新文件的意思。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -tf all.tar 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这条命令是列出all.tar包中所有文件，-t是列出文件的意思</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -xf all.tar 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这条命令是解出all.tar包中所有文件，-x是解开的意思</p> <h3 id="压缩"><a href="#压缩" class="header-anchor">#</a> 压缩</h3> <p>将目录里所有jpg文件打包成tar.jpg</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar –cvf jpg.tar *.jpg
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>将目录里所有jpg文件打包成jpg.tar后，并且将其用gzip压缩，生成一个gzip压缩过的包，命名为jpg.tar.gz</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar –czf jpg.tar.gz *.jpg
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>将目录里所有jpg文件打包成jpg.tar后，并且将其用bzip2压缩，生成一个bzip2压缩过的包，命名为jpg.tar.bz2</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar –cjf jpg.tar.bz2 *.jpg
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>将目录里所有jpg文件打包成jpg.tar后，并且将其用compress压缩，生成一个umcompress压缩过的包，命名为jpg.tar.Z</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar –cZf jpg.tar.Z *.jpg   //
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>rar格式的压缩，需要先下载rar for linux</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>rar a jpg.rar *.jpg
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>zip格式的压缩，需要先下载zip for linux</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>zip jpg.zip *.jpg
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="解压"><a href="#解压" class="header-anchor">#</a> 解压</h3> <p>解压 tar包</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar –xvf file.tar 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>解压tar.gz</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -xzvf file.tar.gz
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>解压 tar.bz2</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar -xjvf file.tar.bz2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>解压tar.Z</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>tar –xZvf file.tar.Z
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>解压rar</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>unrar e file.rar
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>解压zip</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>unzip file.zip
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>总结</p> <ol><li>*.tar 用 tar –xvf 解压</li> <li>*.gz 用 gzip -d或者gunzip 解压</li> <li>*.tar.gz 和 *.tgz 用 tar –xzf 解压</li> <li>*.bz2 用 bzip2 -d或者用bunzip2 解压</li> <li>*.tar.bz2用tar –xjf 解压</li> <li>*.Z 用 uncompress 解压</li> <li>*.tar.Z 用tar –xZf 解压</li> <li>*.rar 用 unrar e解压</li> <li>*.zip 用 unzip 解压</li></ol></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">3/25/2022, 9:54:21 PM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-3" data-v-cb1513f6><a href="/blog/blogs/Linux/2022032506.html#压缩" class="sidebar-link reco-side-压缩" data-v-cb1513f6>压缩</a></li><li class="level-3" data-v-cb1513f6><a href="/blog/blogs/Linux/2022032506.html#解压" class="sidebar-link reco-side-解压" data-v-cb1513f6>解压</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/blog/assets/js/app.eeaaf521.js" defer></script><script src="/blog/assets/js/3.f4973d30.js" defer></script><script src="/blog/assets/js/1.c6353690.js" defer></script><script src="/blog/assets/js/15.3a0e6f2f.js" defer></script>
  </body>
</html>
